<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
    <!--{include file='comm/header.tpl'}-->
    	<title>中分类列表</title>
    <!--{include file='comm/comm_pic.tpl'}-->
</head>

<body>
<div style="width:100%">
    <div class="items clearfix">
        <h2 style="" class="tal">
        	小分类列表(上级中分类：<!--{$cateTitle}-->)
        </h2>
        <div class="items2">
			<div>
                <form id="selector_form" onsubmit="return false;">
                    <div style="width:925px;">
						<table id="flex" style="width:100%;padding-bottom:0px;">
							
						</table>
					</div>
                </form>
            </div>
        </div>
    </div>


</div>
<script type="text/javascript">
	//表格对象
	var table_obj = {'page' : '', 'total' : '', 'rows' : []};
	
	$("#flex").flexigrid({
        url:"",
        dataType: "json",
        colModel : [
            {display: "操作", width : 120, align: "center"},
            {display: "小分类号", width : 90},
            {display: "小分类名称", width : 330},
            {display: "分类类型", width : 90, align: "center"},
            {display: "使用状态", width : 90 , align: "center"},
            {display: "排序", width : 90, align: "center"}
        ],
         buttons : [
            {name: "删除", bclass: "delete", onpress : "smallCategory.delete"}
        ],
        useRp: false,
        showTableToggleBtn: true,
    });

    var smallCategory = {
    	
    	delete_str: '' ,
    	useFlg_str : '' ,
    	
         //添加一行
		 tr_fun : function(id, value){

			table_obj.rows.push({'id' : id, 'cell' : value});
        	
        	$("#flex").flexAddData(table_obj);	
			
        },
        
        //修改
        edit: function(categoryID) {
            E.open("/quanliadmin/app/goods/goodsCategory.pscript?operFlg=3&categoryID=" + categoryID, "", {height: 600,width: 1024, top: 50, left: 150});
        },
        
        //查看
        view : function(smallCategoryID){
        	 E.open("/quanliadmin/app/goods/goodsCategory.pscript?operFlg=5&smallCategoryID=" + smallCategoryID, "", {height: 600,width: 1024, top: 50, left: 150});
        },
        
        //启用、禁用
        doAction: function( categoryStr , useFlg ) {
            this.useFlg_str = categoryStr + "_" + useFlg ;
            if( useFlg == 0 )
            	E.confirm("您确认要禁用分类吗？", "smallCategory.actionConfirm");
            else
            	smallCategory.actionConfirm() ;
        },
        
         actionConfirm : function () {
            $.ajax({
                type: "POST",
                url: "/invokingAjax-backend/goods/category.ajax?operFlg=5&useFlg_str=" + smallCategory.useFlg_str,
                dataType: "JSON",
                success: function( result_obj ) {
                    if (result_obj.code == 200) {
                        E.alert(result_obj.message, 2, "E.refresh");
                    } else {
                        E.alert(result_obj.message);
                    }
                }
            });
        },
        
        load: function() {
            $("#flex").flexReload();
        },
        
        //删除小分类
        delete: function() {
            this.delete_str = "";
            $.each($("#flex").find("tr"), function(k, v) {
                if ($(v).hasClass("trSelected")) {
                    smallCategory.delete_str += "_" + $(v).attr("id").replace("row", "");
                }
            });
			
            if (this.delete_str == "")
                E.alert("请选择删除分类");
            else
                E.confirm("您确认要删除选中的分类吗？", "smallCategory.deleteConfirm");
        },
        
         deleteConfirm: function() {
            this.delete_str = this.delete_str.substr(1);
            $.ajax({
                type: "POST",
                url: "/invokingAjax-backend/goods/category.ajax?operFlg=4&delete_str=" + smallCategory.delete_str,
                dataType: "JSON",
                success: function( result_obj ) {
                    if (result_obj.code == 200) {
                        E.alert(result_obj.message, 2, "E.refresh");
                    } else {
                        E.alert(result_obj.message);
                    }
                }
            });
        },
        
    };

    //编辑初始化显示选择器
    $(document).ready(function() {
		<!--{if $smallData}-->
			<!--{foreach from=$smallData item=rule}-->
				var id = '<!--{$rule->bigCategoryID}-->_<!--{$rule->midCategoryID}-->_<!--{$rule->smallCategoryID}-->';
				var rowID = '<!--{$rule->bigCategoryID}-->-<!--{$rule->midCategoryID}-->-<!--{$rule->smallCategoryID}-->';
				var editor    = '<a href="javascript: void(0);" onclick=smallCategory.edit("'+id+'");>修改</a>';
				var smallID   = '<!--{$rule->smallCategoryID}-->';
				var smallText = '<!--{$rule->description}-->';
				var smallType = '小分类';
				var useFlg = '';
				var use = '<!--{$rule->useFlg}-->';
				if(use == 1)
					useFlg = '<a href="javascript: void(0);" onclick=smallCategory.doAction("'+id+'",0);>启用</a>';
				else
					useFlg = '<a href="javascript: void(0);" onclick=smallCategory.doAction("'+id+'",1); >禁用</a>';
	        			
	        	var sortOrder = '<!--{$rule->sortOrder}-->';		
				
				var value = [editor, smallID, smallText, smallType, useFlg, sortOrder];
				smallCategory.tr_fun(rowID, value);
			<!--{/foreach}-->
		<!--{/if}-->
    });
</script>

</body>

</html>
